package com.bonc.wkafka.utils;

import java.util.Properties;

import org.apache.kafka.clients.consumer.ConsumerRecord;

public class KafkaProps {
	
	protected final Properties props = new Properties();
	
	protected KafkaProps setProp(String key, Object value) {
		this.props.put(key, value);
        return this;
    }
	
    /**
     * Defines how the {@link KafkaSpout} seeks the offset to be used in the first poll to Kafka upon topology deployment.
     * By default this parameter is set to UNCOMMITTED_EARLIEST. 
     */
    public enum FirstPollOffsetStrategy {
        /**
         * The kafka spout polls records starting in the first offset of the partition, regardless of previous commits. This setting only
         * takes effect on topology deployment
         */
        EARLIEST,
        /**
         * The kafka spout polls records with offsets greater than the last offset in the partition, regardless of previous commits. This
         * setting only takes effect on topology deployment
         */
        LATEST,
        /**
         * The kafka spout polls records from the last committed offset, if any. If no offset has been committed it behaves as EARLIEST
         */
        UNCOMMITTED_EARLIEST,
        /**
         * The kafka spout polls records from the last committed offset, if any. If no offset has been committed it behaves as LATEST
         */
        UNCOMMITTED_LATEST;

        @Override
        public String toString() {
            return "FirstPollOffsetStrategy{" + super.toString() + "}";
        }
    }
    
    /**
     * This enum controls when the tuple with the {@link ConsumerRecord} for an offset is marked as processed,
     * i.e. when the offset can be committed to Kafka. The default value is AT_LEAST_ONCE.
     * The commit interval is controlled by {@link KafkaSpoutConfig#getOffsetsCommitPeriodMs() }, if the mode commits on an interval.
     * NO_GUARANTEE may be removed in a later release without warning, we're still evaluating whether it makes sense to keep.
     */
    public enum ProcessingGuarantee {
        /**
         * An offset is ready to commit only after the corresponding tuple has been processed and acked (at least once). If a tuple fails or
         * times out it will be re-emitted, as controlled by the {@link KafkaSpoutRetryService}. Commits synchronously on the defined
         * interval.
         */
        AT_LEAST_ONCE,
        /**
         * Every offset will be synchronously committed to Kafka right after being polled but before being emitted to the downstream
         * components of the topology. The commit interval is ignored. This mode guarantees that the offset is processed at most once by
         * ensuring the spout won't retry tuples that fail or time out after the commit to Kafka has been done
         */
        AT_MOST_ONCE,
        /**
         * The polled offsets are ready to commit immediately after being polled. The offsets are committed periodically, i.e. a message may
         * be processed 0, 1 or more times. This behavior is similar to setting enable.auto.commit=true in the consumer, but allows the
         * spout to control when commits occur. Commits asynchronously on the defined interval.
         */
        NO_GUARANTEE,
    }
    
    public enum SendPattern {
    	FORGOTTEN,
    	SYNC,
    	ASYNC,
    }
    
    public enum ConsumerModel {
    	CONSUMER_GROUP,
    	STANDALONE_CONSUMER,
    }
}
